package experiment;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import Entities.Calendar;
import Entities.CoursesConfiguration;
import Entities.ParseCsv;
import algorithms.HillClimbing;


public abstract class BaseExperiment implements IExperiment {

	protected static List<CoursesConfiguration> courseConfigurations;
	
	// C'tor
	public BaseExperiment() {
		courseConfigurations = new LinkedList<CoursesConfiguration>();
		initRandSeed();
	}

	private void initRandSeed(){
		Calendar.initSeed();
		HillClimbing.initSeed();
	}
	
	public static void setCourseConfigurations(String pathName) throws IOException {
		if(pathName == null) {
			throw new IOException("Recieved null");
		}
		courseConfigurations.clear(); // clear previous courses
		File dir = new File(pathName);
		File[] dirFiles = null;
		if(dir.exists() && dir.isDirectory()){
			dirFiles = dir.listFiles();
		}
		
		for (int i = 200 ; i < NUMBER_OF_COURSES_CONFIGURATIONS ; i++) 
		{
			File file = dirFiles[i];
			if (!file.isDirectory())
			{
				courseConfigurations.add(new CoursesConfiguration(ParseCsv.parse(file), file.toString()));				
			}
		}
	}
	
    public String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
	
}